package com.tts.hbdao;

import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

import com.tts.hbentity.Line;

/**
 * Data access object (DAO) for domain model class Line.
 * 
 * @see com.tts.hbentity.Line
 * @author MyEclipse Persistence Tools
 */

public class LineDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(LineDAO.class);
	// property constants
	public static final String LINE_NAME = "lineName";
	public static final String LINE_TOTAL_FEE = "lineTotalFee";
	public static final String LINE_TRAFFIC = "lineTraffic";
	public static final String LINE_START_TIME = "lineStartTime";
	public static final String LINE_INTRODUCE = "lineIntroduce";
	public static final String LINE_LEVEL = "lineLevel";
	public static final String COMPANY_ID = "companyId";
	public static final String LINE_STATUS = "lineStatus";

	public void save(Line transientInstance) {
		log.debug("saving Line instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Line persistentInstance) {
		log.debug("deleting Line instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Line findById(java.lang.Integer id) {
		log.debug("getting Line instance with id: " + id);
		try {
			Line instance = (Line) getSession().get("com.tts.hbdao.Line", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Line instance) {
		log.debug("finding Line instance by example");
		try {
			List results = getSession().createCriteria("com.tts.hbdao.Line")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Line instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Line as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByLineName(Object lineName) {
		return findByProperty(LINE_NAME, lineName);
	}

	public List findByLineTotalFee(Object lineTotalFee) {
		return findByProperty(LINE_TOTAL_FEE, lineTotalFee);
	}

	public List findByLineTraffic(Object lineTraffic) {
		return findByProperty(LINE_TRAFFIC, lineTraffic);
	}

	public List findByLineStartTime(Object lineStartTime) {
		return findByProperty(LINE_START_TIME, lineStartTime);
	}

	public List findByLineIntroduce(Object lineIntroduce) {
		return findByProperty(LINE_INTRODUCE, lineIntroduce);
	}

	public List findByLineLevel(Object lineLevel) {
		return findByProperty(LINE_LEVEL, lineLevel);
	}

	public List findByCompanyId(Object companyId) {
		return findByProperty(COMPANY_ID, companyId);
	}

	public List findByLineStatus(Object lineStatus) {
		return findByProperty(LINE_STATUS, lineStatus);
	}

	public List findAll() {
		log.debug("finding all Line instances");
		try {
			String queryString = "from Line";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Line merge(Line detachedInstance) {
		log.debug("merging Line instance");
		try {
			Line result = (Line) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Line instance) {
		log.debug("attaching dirty Line instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Line instance) {
		log.debug("attaching clean Line instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}